/* eslint-disable */
import { _decorator, Enum, Label } from 'cc';
import { LogUtil } from '../../Util/LogUtil';
import { NodeRecycle } from '../Manager/PoolManager';
const { ccclass, property, menu } = _decorator;

export enum ListRenderTag {
  Myself,
  Label,
  Button,
  Skeleton,
  DropdownBox,
  EditBox,
  SpriteFrame,
}

export class ListLayerData {
  titleData: unknown;
  detailsData: unknown[];
  constructor(titleData: unknown, detailsData: unknown[]) {
    this.titleData = titleData;
    this.detailsData = detailsData;
  }
}

@ccclass('ListRender')
@menu('myComponent/ListRender')
export class ListRender extends NodeRecycle {
  @property({ type: Enum(ListRenderTag) })
  itemTag: ListRenderTag = ListRenderTag.Myself;

  itemIndex: number = 0;
  data: unknown;
  dataChanged(...args: unknown[]) {
    switch (this.itemTag) {
      case ListRenderTag.Label:
        this.node.getComponent(Label).string = this.data as string;
        break;
      case ListRenderTag.Button:
        this.node.getChildByName('Label').getComponent(Label).string = this.data as string;
        LogUtil.e('ListRender', '这里使用button组件，cocos会有一个重复添加scrollView的error，不影响使用，建议使用list的回调实现点击');
        break;
      case ListRenderTag.Myself:
        {
          const lab = this.node.getChildByName('Label');
          lab.getComponent(Label).string = this.data as string;
        }
        break;
      default:
        LogUtil.e('ListRender', '这里不实现item的具体逻辑，继承ListItem实现自己的逻辑');
        break;
    }
  }
  onEnableDoing(space: number) {}

  reuse() {}
  unuse() {}
}
